package com.leonzhangxf.guice;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.leonzhangxf.guice.bill.*;
import com.leonzhangxf.guice.bill.domain.CreditCard;
import com.leonzhangxf.guice.bill.domain.Order;
import com.leonzhangxf.guice.bill.domain.Receipt;

import java.util.Map;

/**
 * Guice demo
 *
 * @author leonzhangxf 20190219
 */
public class GuiceApplication {

    public static void main(String[] args) {
        Injector injector = Guice.createInjector(new MainModule());
        BillingService billingService = injector.getInstance(BillingService.class);

        Order order = new Order(10);
        CreditCard creditCard = new CreditCard("leon-cart", 1000, 2019);
        Receipt receipt = billingService.chargeOrder(order, creditCard);

        System.out.println(creditCard);
        System.out.println(receipt);

        Map<String, String> map = injector.getInstance(
            Key.get(new TypeLiteral<Map<String, String>>() {}, ConfigMap.class));
        System.out.println(map);
    }
}
